/*
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is ST_EXT-S_UIMAST.
 *
 * The Initial Developer of the Original Code is
 * University of Rome, Tor Vergata
 * Portions created by the Initial Developer are Copyright (C) 2009
 * the Initial Developer. All Rights Reserved.
 */

/**
 * Opens the type system editor in a new tab.
 */
function uimast_openTypeSystemEditor()
{
	getBrowser().selectedTab = getBrowser().addTab('chrome://uimast/content/type_system_editor/type_system_editor.xul')
	// the assignement to the selectedTab property is needed to select the newly created tab
}

/**
 * Opens the projection editor in a new tab.
 */
function uimast_openProjectionEditor()
{
	getBrowser().selectedTab = getBrowser().addTab('chrome://uimast/content/projection_editor/projection_editor.xul')
	// the assignement to the selectedTab property is needed to select the newly created tab
}

/**
 * Opens the dialog to export the annotations.
 */
function uimast_exportAnnotations()
{
	// Opens a modal window to choose the export options
	window.openDialog("chrome://uimast/content/export_annotations_dialog.xul", "dlg", "modal").focus();
}


/**
 * First run checks. 
 */
function uimast_firstrun_checks()
{
	// Gets the preferences service
	var Prefs = Components.classes["@mozilla.org/preferences-service;1"]
	                      .getService(Components.interfaces.nsIPrefService);

	// Gets the extension preferences
	Prefs = Prefs.getBranch("extensions.semturkey.extpt.uimast.");
    
    var ver = -1;

	// Gets the extension version
    var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"]
	                                  .getService(Components.interfaces.nsIExtensionManager);
    var current = gExtensionManager.getItemForID("uimast@art.uniroma2.it").version;
    	
    try{
    	// Gets the version number
		ver = Prefs.getCharPref("version");
    }catch(e){
      // do nothing if the preferences aren't set: it's a first run
    }finally{
      if (ver != current){
        // Registers the current version in the preferences
        Prefs.setCharPref("version",current);
	
       	// Gets the annotation type
		var Prefs = Components.classes["@mozilla.org/preferences-service;1"]
		                      .getService(Components.interfaces.nsIPrefService);

		var annotate = Prefs.getCharPref("extensions.semturkey.extpt.annotate");
		
		// Warn if the current annotation type isn't xpointerAnnotation
		if (annotate != "xpointerAnnotation" ) {
			window.openDialog("chrome://uimast/content/firstrun_checks.xul", "", "chrome, dialog, modal, resizable=yes", null).focus();
		}		
      }		
    }
    
	window.removeEventListener("load", uimast_firstrun_checks, true);
}
